package com.lanou.controller;

import com.lanou.utils.VerifyCodeUtils;
import com.lanou.utils.code.VerifyCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

@Api(value = "生成验证码",tags = "生成验证码")
@RestController
@RequestMapping("/VerifyCode")
public class VerifyCodeController {
@ApiOperation(value = "生成验证码",httpMethod = "GET")
@RequestMapping("/getCode")
public void getCode(HttpServletResponse response) throws IOException {
String code = VerifyCodeUtils.generateVerifyCode(4);
int w = 200, h = 80;
OutputStream outputStream = response.getOutputStream();
VerifyCodeUtils.outputImage(w,h,outputStream,code);
VerifyCode.getInstance().setCode(code);
outputStream.close();
}
}